/**
 * @name constant.js
 * @description 常量定义
 * @author 'fwq'
 * @time 2021/10/17
 */
import { UUID2 } from "./utils";
import { isString } from 'lodash-es'

const fontUrl = "//at.alicdn.com/t/font_2638773_92rs8q9jxg8.css";
const baseUrl = import.meta.env.VITE_APP_URL;
const etlType = [
  "compute",
  "filter",
  "merge",
  "isnull",
  "distinct",
  "select",
  "order",
  "const",
  "group",
  "change",
  "rtc",
  "ctr",
  "alias",
  "format",
  "output",
  "congroup",
];
const draggableOption = {
  parent: true,
  scale: 1,
  draggable: true, // 定义组件是否可以拖动。
  resizable: true, // 定义组件是否可以调整大小。
  grid: [1, 1],
};

const SketchRuleOption = {
  lang: "zh-CN",
  scale: 1, //658813476562495, //1,
  thick: 22, // thick size 辅助尺 大小
  width: 1920,
  height: 860,
  startX: -30, // x at the beginning of the ruler
  startY: -30,
  shadow: {
    x: 0,
    y: 0,
    width: 0,
    height: 0,
  }, // 阴影标尺上的大小和起始坐标
  lines: {
    // 默认显示辅助线位置
    h: [],
    v: [],
  },
  cornerActive: true,
  palette: {
    bgColor: "#0e1013",
    longFgColor: "#494f53",
    shortFgColor: "#494f53",
    fontColor: "#bcc9d4",
    shadowColor: "transparent",
    lineColor: "#2196f3",
    borderColor: "rgba(161,174,179,.6)",
    cornerActiveColor: "#fff",
  },
};
/**
 * 构建 绝对布局布局块对象
 * @param payload
 * @returns
 */
const AbsoluteLayoutItem = function () {
  let layoutItem = {
    id: UUID2(16),
    layoutConfigData: {
      width: 1920,
      widthPixelUnit: "px",
      height: 1080,
      heightPixelUnit: "px",
      backgroundColor: "#0E2B43",
      syncSetPageBgColor: true,
      dragPixel: 1,
      thumbnailPath: "",
      imageRelativePath: "",
      backgroundRepeat: "no-repeat",
      backgroundSize: "100% 100%",
      styleFilter_use: false,
      styleFilter_hueRotate: 0,
      styleFilter_contrast: 100,
      styleFilter_opacity: 100,
      styleFilter_saturate: 100,
      styleFilter_brightness: 100,
      customStyleCode: "",
      layoutItems: [],
    },
  };

  return layoutItem;
};

function setDataSourceConfig (
  config,
  compId,
  staticData,
  data,
  type = "static"
) {
  config.source = {
    // id
    id: UUID2(6),
    // 组件Id
    compId,
    type,
    requestId: "",
    requestData: [],
    // 包含的字段
    fields: {},
    render: "render",
    // 自动更新
    useAutoUpdate: false,
    // 自动更新时间
    autoUpdate: 1,
    dataFilters: [],
    config: {
      useFilter: false,
      data: isString(data) ? data : JSON.stringify(data),
    },
    staticData,
  };
  return config;
}
// UUID3(8)
const commonAttr = {
  alias: "组",
  animations: [],
  attr: {
    top: 0,
    left: 0,
    width: 0,
    height: 0,
    rotate: 0,
    opacity: 1,
    borderRadius: 0,
    borderStyle: "solid",
    borderWidth: 0,
    bgColor: "transparent",
  },
  children: [],
  config: {
  },
  events: [],
  groupAttr: {},
  hided: false,
  hovered: false,
  icon: "icon-wenjianjia",
  locked: false, // 是否锁定组件
  name: "group",
  type: "van-group",
  selected: false,
}

/** total loading  */
const loadingSvg = `<circle
    cx="25"
    cy="25"
    r="20"
    fill="transparent"
    stroke-width="3"
    stroke-dasharray="31.415, 31.415"
    stroke="#02bcfe"
    stroke-linecap="round"
  >
    <animateTransform
      attributeName="transform"
      type="rotate"
      values="0, 25 25;360, 25 25"
      dur="1.5s"
      repeatCount="indefinite"
    />
    <animate
      attributeName="stroke"
      values="#02bcfe;#3be6cb;#02bcfe"
      dur="3s"
      repeatCount="indefinite"
    />
  </circle>

  <circle
    cx="25"
    cy="25"
    r="10"
    fill="transparent"
    stroke-width="3"
    stroke-dasharray="15.7, 15.7"
    stroke="#3be6cb"
    stroke-linecap="round"
  >
    <animateTransform
      attributeName="transform"
      type="rotate"
      values="360, 25 25;0, 25 25"
      dur="1.5s"
      repeatCount="indefinite"
    />
    <animate
      attributeName="stroke"
      values="#3be6cb;#02bcfe;#3be6cb"
      dur="3s"
      repeatCount="indefinite"
    />
  </circle>`;


/** etl baseConfig  */
const baseConfig = {
  status: false,
  originFields: [],
};

/** etl libs  */
const etl_libs = [
  {
    id: "1",
    name: "数据集",
    children: [
      {
        id: "11",
        type: "input",
        typeName: "输入数据集",
        nodeName: "输入数据集",
        ...baseConfig,
        icon: "icon-shy",
        config: { table: "", limit: 1000, fields: [] },
      },
      {
        id: "12",
        type: "output",
        typeName: "输出数据集",
        nodeName: "输出数据集",
        ...baseConfig,
        config: {
          fields: [],
        },
        icon: "icon-wajue_shujushuchu",
      },
    ],
  },
  {
    id: "2",
    name: "列编辑",
    children: [
      {
        id: "21",
        type: "compute",
        typeName: "添加计算列",
        nodeName: "添加计算列",
        ...baseConfig,
        config: {
          fields: [], // 原有数据列
          computes: [],
        },
        icon: "icon-tianjiajisuan",
      },
      {
        id: "22",
        type: "merge",
        typeName: "列合并",
        nodeName: "列合并",
        ...baseConfig,
        icon: "icon-hebinglie",
        config: {
          rowName: "",
          rows: [],
          fields: [], // 原有数据列
          deleteRows: false,
          separator: "", // '' ',' ';' 'tab' ' '
        },
      },
      {
        id: "26",
        type: "select",
        typeName: "选择列",
        nodeName: "选择列",
        ...baseConfig,
        config: { selectFields: [], fields: [] },
        icon: "icon-select_columns",
      },
      {
        id: "27",
        type: "rtc",
        typeName: "行转列",
        nodeName: "行转列",
        ...baseConfig,
        config: {
          groupName: "",
          dataColumn: "",
          nameColumn: "",
          dataRtc: [],
          fields: [],
        },
        icon: "icon-hangzhuanlie",
      },
      {
        id: "28",
        type: "ctr",
        typeName: "列转行",
        nodeName: "列转行",
        ...baseConfig,
        config: {
          groupName: "",
          changeValue: "",
          changeColumn: "",
          fields: [],
        },
        icon: "icon-liezhuanhang",
      },
      {
        id: "29",
        type: "const",
        typeName: "常量列",
        nodeName: "常量列",
        ...baseConfig,
        config: { con: {}, fields: [] },
        icon: "icon-changliang",
      },
      {
        id: "212",
        type: "congroup",
        typeName: "自定义分组列",
        nodeName: "自定义分组列",
        ...baseConfig,
        config: {
          fields: [],
          groupFiled: "",
          congroup: [],
          alias: "",
          type: "varchar",
        },
        icon: "icon-changliang",
      },
      {
        id: "210",
        type: "alias",
        typeName: "列名转换",
        nodeName: "列名转换",
        ...baseConfig,
        config: { fields: [] },
        icon: "icon-xiugaibiaoti",
      },
      {
        id: "211",
        type: "format",
        typeName: "格式化数据",
        nodeName: "格式化数据",
        ...baseConfig,
        config: {
          fields: [],
          field: "",
          type: "",
          timeType: "",
          isNum: false,
          isPrefix: false,
          prefix: "",
          isSuffix: false,
          suffix: "",
          numLen: 0,
          numTimeType: 1,
          numberMethods: "numDot",
        },
        icon: "icon-shujugeshihua",
      },
    ],
  },
  {
    id: "3",
    name: "数据编辑",
    children: [
      {
        id: "31",
        type: "filter",
        typeName: "筛选数据行",
        nodeName: "筛选数据行",
        ...baseConfig,
        config: { condition: [], fields: [] },
        icon: "icon-icon_biaogeshaixuan",
      },
      {
        id: "32",
        type: "distinct",
        typeName: "去重",
        nodeName: "去重",
        ...baseConfig,
        config: { fields: [] },
        icon: "icon-quzhong",
      },
      {
        id: "33",
        type: "change",
        typeName: "值转换",
        nodeName: "值转换",
        ...baseConfig,
        config: {
          column: "",
          deleteRows: false,
          alias: "",
          isDefault: true,
          defaultValue: "",
          change: [],
          fields: [],
        },
        icon: "icon-zhitihuan",
      },
      {
        id: "34",
        type: "isnull",
        typeName: "Null值替换",
        nodeName: "Null值替换",
        ...baseConfig,
        config: { isnull: [], fields: [] },
        icon: "icon-changeNull",
      },
      {
        id: "35",
        type: "order",
        typeName: "排序",
        nodeName: "排序",
        ...baseConfig,
        config: { order: [], fields: [] },
        icon: "icon-paixubeifen",
      },
      {
        id: "36",
        type: "group",
        typeName: "统计",
        nodeName: "统计",
        ...baseConfig,
        config: { groups: [], fields: [] },
        icon: "icon-ETL_fenzujuhe",
      },
    ],
  },
  {
    id: "4",
    name: "数据集组合",
    icon: "el-icon-video-pause",
    children: [
      {
        id: "41",
        type: "union",
        typeName: "行拼接",
        nodeName: "行拼接",
        ...baseConfig,
        config: { union: [], fields: [] },
        icon: "icon-ETL_hangpinjie",
      },
      {
        id: "23",
        type: "join",
        typeName: "连接",
        nodeName: "连接",
        ...baseConfig,
        icon: "icon-zuolianjie",
        sourceNode: {},
        originNode: {},
        config: {
          join: {},
          fields: [],
        },
      },
    ],
  },
];

/** etl numbertype  */
const numberType = [
  "tinyint",
  "smallint",
  "mediumint",
  "int",
  "integer",
  "bigint",
  "float",
  "double",
  "decimal",
  "numeric",
  "smallserial",
  "serial",
  "bigserial",
  "double precision",
  "real",
  "money",
];

/** etl dateType  */
const dateType = [
  "date",
  "time",
  "year",
  "datetime",
  "timestamp",
  "timestamptz",
];

/** etl charType  */
const charType = [
  "char",
  "varchar",
  "character",
  "tinyblob",
  "tinytext",
  "blob",
  "text",
  "mediumblob",
  "mediumtext",
  "longblob",
  "longtext",
  "enum",
  "set",
];


export {
  fontUrl,
  baseUrl,
  draggableOption,
  SketchRuleOption,
  AbsoluteLayoutItem,
  setDataSourceConfig,
  commonAttr,
  loadingSvg,
  etlType,
  numberType,
  dateType,
  charType,
  etl_libs,
};
